<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Section 6.1.2: Residual minimization with deadzone penalty</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/cvxbook/Ch06_approx_fitting/html/deadzone.html">
<link rel="stylesheet" href="../../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Section 6.1.2: Residual minimization with deadzone penalty</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Boyd &amp; Vandenberghe "Convex Optimization"</span>
<span class="comment">% Joelle Skaf - 08/17/05</span>
<span class="comment">%</span>
<span class="comment">% The penalty function approximation problem has the form:</span>
<span class="comment">%               minimize    sum(deadzone(Ax - b))</span>
<span class="comment">% where 'deadzone' is the deadzone penalty function</span>
<span class="comment">%               deadzone(y) = max(abs(y)-1,0)</span>

<span class="comment">% Input data</span>
randn(<span class="string">'state'</span>,0);
m = 16; n = 8;
A = randn(m,n);
b = randn(m,1);

<span class="comment">% deadzone penalty</span>
<span class="comment">% original formulation</span>
fprintf(1,<span class="string">'Computing the optimal solution of the deadzone approximation problem: \n'</span>);

cvx_begin
    variable <span class="string">x(n)</span>
    minimize( sum(max(abs(A*x-b)-1,0)) )
cvx_end

fprintf(1,<span class="string">'Done! \n'</span>);

<span class="comment">% Compare</span>
disp( sprintf( <span class="string">'\nResults:\n--------\nsum(max(abs(A*x-b)-1,0)): %6.4f\ncvx_optval: %6.4f\ncvx_status: %s\n'</span>, sum(max(abs(A*x-b)-1,0)), cvx_optval, cvx_status ) );
disp( <span class="string">'Optimal vector:'</span> );
disp( [ <span class="string">'   x     = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, x ), <span class="string">']'</span> ] );
disp( <span class="string">'Residual vector:'</span> );
disp( [ <span class="string">'   A*x-b = [ '</span>, sprintf( <span class="string">'%7.4f '</span>, A*x-b ), <span class="string">']'</span> ] );
disp( <span class="string">' '</span> );
</pre>
<a id="output"></a>
<pre class="codeoutput">
Computing the optimal solution of the deadzone approximation problem: 
 
Calling SDPT3: 72 variables, 32 equality constraints
------------------------------------------------------------

 num. of constraints = 32
 dim. of socp   var  = 32,   num. of socp blk  = 16
 dim. of linear var  = 32
 dim. of free   var  =  8 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|7.4e-01|2.3e+01|1.8e+04| 2.252324e+02  0.000000e+00| 0:0:00| chol  1  1 
 1|1.000|0.835|2.4e-06|3.9e+00|1.5e+03| 2.732368e+02 -3.160464e+01| 0:0:00| chol  1  1 
 2|1.000|0.988|4.3e-06|5.6e-02|1.6e+02| 1.373391e+02 -1.280265e+01| 0:0:00| chol  1  1 
 3|0.896|0.969|1.6e-06|2.6e-03|1.7e+01| 6.468687e+00 -1.056104e+01| 0:0:00| chol  1  1 
 4|1.000|0.029|3.5e-06|3.2e-03|1.7e+01| 5.676729e+00 -1.024814e+01| 0:0:00| chol  1  1 
 5|0.649|0.474|2.0e-06|1.7e-03|1.1e+01| 4.684397e+00 -5.922458e+00| 0:0:00| chol  1  1 
 6|0.929|0.307|5.9e-07|1.2e-03|6.5e+00| 1.975882e+00 -4.346206e+00| 0:0:00| chol  1  1 
 7|1.000|0.416|3.9e-07|6.9e-04|3.5e+00| 7.427569e-01 -2.708758e+00| 0:0:00| chol  1  1 
 8|1.000|0.554|1.0e-07|3.1e-04|1.5e+00| 1.716839e-01 -1.269672e+00| 0:0:00| chol  1  1 
 9|0.999|0.891|1.8e-08|3.4e-05|1.5e-01| 5.764868e-03 -1.408961e-01| 0:0:00| chol  1  1 
10|0.987|0.986|1.3e-09|4.8e-07|2.1e-03| 7.881245e-05 -2.003151e-03| 0:0:00| chol  1  1 
11|0.989|0.989|6.3e-11|1.0e-05|7.1e-05| 8.706354e-07 -2.251729e-05| 0:0:00| chol  1  1 
12|1.000|0.988|8.2e-14|3.5e-07|2.2e-06| 1.560505e-07 -5.703411e-07| 0:0:00| chol  1  1 
13|1.000|0.988|4.5e-15|1.1e-08|6.6e-08| 4.842106e-09 -1.628348e-08| 0:0:00| chol  1  1 
14|1.000|0.912|2.3e-16|4.0e-10|2.0e-08| 6.148509e-09 -1.262963e-08| 0:0:00| chol  1  1 
15|1.000|0.607|3.8e-15|1.4e-10|8.7e-09| 1.449139e-09 -6.710838e-09| 0:0:00|
  stop: max(relative gap, infeasibilities) &lt; 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 15
 primal objective value =  1.44913897e-09
 dual   objective value = -6.71083793e-09
 gap := trace(XZ)       = 8.69e-09
 relative gap           = 8.69e-09
 actual relative gap    = 8.16e-09
 rel. primal infeas     = 3.75e-15
 rel. dual   infeas     = 1.38e-10
 norm(X), norm(y), norm(Z) = 4.0e+00, 4.6e-09, 4.0e+00
 norm(A), norm(b), norm(C) = 1.7e+01, 6.4e+00, 5.0e+00
 Total CPU time (secs)  = 0.23  
 CPU time per iteration = 0.02  
 termination code       =  0
 DIMACS: 9.6e-15  0.0e+00  3.4e-10  0.0e+00  8.2e-09  8.7e-09
-------------------------------------------------------------------
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +1.44914e-09
 
Done! 

Results:
--------
sum(max(abs(A*x-b)-1,0)): 0.0000
cvx_optval: 0.0000
cvx_status: Solved

Optimal vector:
   x     = [  0.3334  0.0993 -0.3344  0.0608  0.6061  0.3877 -0.6685  0.7438 ]
Residual vector:
   A*x-b = [  0.6199  0.3678 -0.8146 -0.2921  0.3308  0.4011 -0.6790 -0.7038 -0.4704  0.7816  0.0804 -0.0987  0.5240  0.7539  0.2686 -0.3702 ]
 
</pre>
</div>
</body>
</html>